package org.jeecg.modules.api.wlhy.driver;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.system.base.controller.JeecgController;
import org.jeecg.common.system.query.QueryGenerator;
import org.jeecg.modules.paycenter.channel.bankdocking.service.NhBankService;
import org.jeecg.modules.wlhy.bill.entity.HyDriverBill;
import org.jeecg.modules.wlhy.bill.service.IHyDriverBillService;
import org.jeecg.modules.wlhy.hydriver.entity.HyDriver;
import org.jeecg.modules.wlhy.utils.UserUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

@Api(tags="司机流水单")
@RestController
@RequestMapping("/api/wlhy/driver/bill")
@Slf4j
public class ApiDriverBillController extends JeecgController<HyDriverBill, IHyDriverBillService> {
    @Autowired
    private IHyDriverBillService hyDriverBillService;
//    @Autowired
//    private IHyDriverService hyDriverService;

    @Autowired private UserUtil userUtil;

//    @AutoLog(value = "司机流水单分页列表查询")
    @ApiOperation(value="司机流水单分页列表查询", notes="司机流水单分页列表查询")
    @GetMapping(value = "/getTotal")
    public Result<?> getTotal() {
        HyDriver driver = userUtil.getDriver();
        Map<String, String> totalAmtByDriver = hyDriverBillService.getTotalAmtByDriverId(driver.getId() , NhBankService.CHANNEL);
        return Result.OK(totalAmtByDriver);
    }


    @ApiOperation(value="司机流水单分页列表查询", notes="司机流水单分页列表查询")
    @GetMapping(value = "/list")
    public Result<?> queryPageList(HyDriverBill hyDriverBill,
                                   @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
                                   @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
                                   HttpServletRequest req) {
        HyDriver driver = userUtil.getDriver();
        QueryWrapper<HyDriverBill> queryWrapper = QueryGenerator.initQueryWrapper(hyDriverBill, req.getParameterMap());
        queryWrapper.eq("driver_id", driver.getId())
                    .eq("resp_source","0").eq("pay_channel", NhBankService.CHANNEL).ne("bill_type","3");
        Page<HyDriverBill> page = new Page<HyDriverBill>(pageNo, pageSize);
        IPage<HyDriverBill> pageList = hyDriverBillService.page(page, queryWrapper);
        return Result.OK(pageList);
    }

}
